package com.yijumao.shop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yijumao.shop.domain.Item;
import com.yijumao.shop.mapper.ItemMapper;
import com.yijumao.shop.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author konley
 * @date 2020-11-02 17:22
 */
@Service
@Transactional
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return itemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Item record) {
        return itemMapper.insert(record);
    }

    @Override
    public Item selectByPrimaryKey(Integer id) {
        return itemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Item> selectAll() {
        return itemMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Item record) {
        return itemMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Item> selectByIflag(int flag) {
        return itemMapper.selectByIflag(flag);
    }

    @Override
    public PageInfo<Item> selectPageByCid(int cid, int pageName, int pageSize) {
        //开启分页
        PageHelper.startPage(pageName,pageSize);
        //待分页数据
        List<Item> items = itemMapper.selectByCid(cid);
        //分页对象
        PageInfo<Item>  pageInfo = new PageInfo<>(items);
        return pageInfo;
    }
}
